<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="static/css/index.css">
    <style>
        .content {
            width: 100%;
            max-width: 1200px;
            margin: 0 auto;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        thead th {
            background-color: #f2f2f2;
            padding: 12px;
            border: 1px solid #ddd;
            text-align: left;
        }
        tbody td {
            padding: 12px;
            border: 1px solid #ddd;
            text-align: left;
        }
        button {
            padding: 5px 10px;
            margin-left: 10px;
            cursor: pointer;
        }
        button:hover {
            background-color: #ddd;
        }
    </style>
</head>

<body>
    <!-- 头部 -->
    <div class="head">
        <h1>设备管理系统</h1>
        <button class="return-btn">←</button>
    </div>
    <!-- 侧边栏 -->
    <div class="aside">
        <ul>
            <li class="homepage">主页</li>
            <li class="pull-down-all back-stage-management">
{#                 {% if current_user.role == 'admin' or current_user.role == 'root'  %}#}
                <div class="pull-down-btn" id="back-stage">用户管理</div>
{#                {% endif %}#}
{#                <ul class="pull-down back-stage-item">#}
{#                   #}
{#                    <li><div class="eqdiv">设备列表</div> </li>#}
{#                    #}
{#                    <li><div class="sediv">个人设备故障维修记录</div> </li>#}
{#                    <li><div class="udiv">用户记录</div> </li>#}
{#                    <li><div class="rediv">借阅记录</div> </li>#}
{#                    <li><div class="efdiv">故障信息</div> </li>#}
{#                </ul>#}
            </li>

            <li>设备管理</li>
             <li class="pull-down-all test-base-management">
                 <div class="pull-down-btn" id="test-base">题库管理</div>
                 <ul class="pull-down test-base-item">
                     <li><a href="/toindex?url=touser&page=1&per_page=10" class="router">用戶</a> </li>
                     <li><a href="/toindex?url=toequipment&page=1&per_page=10">设备</a> </li>
{#                     <li><a href="/add" class="router">试题录入</a> </li>#}
{#                     <li><a href="">组题列表</a> </li>#}
                 </ul>
             </li>
{#             <li class="pull-down-all discipline-management"> #}
{#                 <div class="pull-down-btn" id="discipline">学科管理</div> #}
{#                 <ul class="pull-down discipline-item"> #}
{#                     <li><a href="">学科</a> </li> #}
{#                     <li><a href="">目录</a> </li> #}
{#                     <li><a href="">标签</a> </li> #}
{#                 </ul> #}
{#             </li> #}
{#             <li>面试技巧</li> #}
        </ul>
    </div>
    <!-- 内容 -->
    <!-- <div>
        <iframe class="content" name="mainiframe" src="" id="mainiframe" onload="" frameborder="0"></iframe>
    </div> -->
    {% if eq %}
    <div class="content">
        <table>
            <thead>
                <tr>
                    <th></th>
                    <th>设备号</th>
                    <th>设备名称</th>
                    <th>价格</th>
                    <th>配置</th>
                    <th>厂家名称</th>
                    <th>出厂日期</th>
                    <th>实验室名</th>
                    <th>操作</th> 
                    <th> 
                        <button class="add-btn" data-sequence-id="">
                        添加
                        </button>
                    </th> 
                    <th> 
                        <button class="dels-btn" data-sequence-id="">
                        批量删除
                        </button>
                    </th>   

                </tr>
            </thead>
                {% for item in eq.equipments %}
                <tr>
                    <td><input type="checkbox" name="selected_ids" value="{{ item.equipment_id }}"></td>
                    <td id="eqid">{{item.equipment_id}}</td>
                    <td>{{item.equipment_name}}</td>
                    <td>{{item.price}}</td>
                    <td>{{item.configuration}}</td>
                    <td>{{item.supplier}}</td>
                    <td>{{item.appearance_date}}</td>
                    <td>{{item.laboratory_name}}</td>
                    <td>                                     
                        <button class="delete-btn" data-sequence-id="{{ item.equipment_id }}">
                            删除
                        </button>
                        <button class="edit-btn" data-sequence-id="{{ item.equipment_id }}">修改</button>
                    </td> 
                </tr>
                
                {% endfor %}


             <div class="pagination">
        {% if eq.pagination.current_page > 1 %}
            <a href="{{ url_for('toindex',url='toequipment', page=eq.pagination.current_page - 1, per_page=eq.pagination.items_per_page) }}">&laquo; Previous</a>
        {% endif %}

        <span class="page-number">
            Page {{ eq.pagination.current_page }} of {{ eq.pagination.total_pages }}
        </span>

        {% if eq.pagination.current_page < eq.pagination.total_pages %}
            <a href="{{ url_for('toindex',url='toequipment', page=eq.pagination.current_page + 1, per_page=eq.pagination.items_per_page) }}">Next &raquo;</a>
        {% endif %}
    </div>
{#            <tbody>#}
{#            </tbody>#}
        </table>
    </div>
    {% endif %}
    {% if s %}
    <div class="content">
        <table>
            <thead>
                <tr>
                    <th>维修号</th>
                    <th>设备号</th>
                    <th>故障序号</th>
                    <th>维修日期</th>
                    <th>维修内容</th>
                    <th>改变配置</th>
                    <th>维修金额</th>  
                    <th>维修人</th>
                    <th>备注</th>
                    <th>操作</th>                                     
                </tr>
            </thead>
                {% for item in s.s_list %}
                <tr>
                    <td>{{item.service_id}}</td>
                    <td>{{item.equipment_id}}</td>
                    <td>{{item.sequence_id}}</td>
                    <td>{{item.maintenance_date}}</td>
                    <td>{{item.maintenance_content}}</td>
                    <td>{{item.change_configuration}}</td>
                    <td>{{item.maintenance_count}}</td> 
                    <td>{{item.maintenance_person}}</td>
                    <td>{{item.remark}}</td>  
                    <td>                  
                    <button id="">
                        删除
                    </button>
                    <button>修改</button>
                    </td> 
                </tr>
                {% endfor %}
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    {% endif %}   
    {% if u  %}
    <div class="content">
        <table>
            <thead>
                <tr>
                    <th>用户号</th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>用户类别</th>
                    <th>操作</th>                                    
                </tr>
            </thead>
                {% for item in u.users %}
                <tr>
                    <td>{{item.userId}}</td>
                    <td>{{item.username}}</td>
                    <td>{{item.password}}</td>
                    <td>{{item.role}}</td>
                    <td>                 
                    <button id="">
                        删除
                    </button>
                    <button>修改</button>
                    </td>  
                </tr>
                {% endfor %}
            <tbody>
            </tbody>
          <div class="pagination">
        {% if u.pagination.current_page > 1 %}
            <a href="{{ url_for('toindex',url='touser', page=u.pagination.current_page - 1, per_page=u.pagination.items_per_page) }}">&laquo; Previous</a>
        {% endif %}

        <span class="page-number">
            Page {{ u.pagination.current_page }} of {{ u.pagination.total_pages }}
        </span>

        {% if u.pagination.current_page < u.pagination.total_pages %}
            <a href="{{ url_for('toindex',url='touser', page=u.pagination.current_page + 1, per_page=u.pagination.items_per_page) }}">Next &raquo;</a>
        {% endif %}
    </div>
        </table>
    </div>


    {% endif %}   
    {% if r %}
    <div class="content">
        <table>
            <thead>
                <tr>
                    <th>记录号</th>
                    <th>用户号</th>
                    <th>设备号</th>
                    <th>创建时间</th>
                    <th>类型</th> 
                    <th>是否有效</th> 
                    <th>操作</th>                                  
                </tr>
            </thead>
                {% for item in r.r_list %}
                <tr>
                    <td>{{item.id}}</td>
                    <td>{{item.user_id}}</td>
                    <td>{{item.equipment_id}}</td>
                    <td>{{item.creat_time}}</td>   
                    <td>{{item.type}}</td>
                    <td>{{item.effect}}</td>
                    <td>                                       
                    <button id="">
                        删除
                    </button>
                    <button>修改</button>
                    </td>                 
                </tr>
                {% endfor %}
            <tbody>
            </tbody>
        </table>
    </div>
    {% endif %}    
    {% if eq_f %}
    <div class="content">
        <table>
            <thead>
                <tr>
                    <th></th>
                    <th>故障序号</th>
                    <th>故障名称</th>
                    <th>设备号</th>
                    <th>设备名称</th>
                    <th>故障日期</th>
                    <th>故障信息</th> 
                    <th>经手人</th>   

                    <th>操作</th> 
                    <th> 
                        <button class="add-btn" data-sequence-id="">
                        添加
                        </button>
                    </th> 
                    <th> 
                        <button class="dels-btn" data-sequence-id="">
                        批量删除
                        </button>
                    </th>                                                   

                </tr>
            </thead>
                {% for item in eq_f.users %}
                <tr>
                    <td><input type="checkbox" name="selected_ids" value="{{ item.sequence_id }}"></td>
                    <td>{{item.sequence_id}}</td>
                    <td>{{item.sequence_name}}</td>
                      <td>{{item.Equipment.equipment_id}}</td>
                    <td>{{item.Equipment.equipment_name}}</td>
                    <td>{{item.failure_date}}</td>   
                    <td>{{item.fault_message}}</td>
                    <td>{{item.person}}</td>  
                    <td>                                     
                    <button class="delete-btn" data-sequence-id="{{ item.sequence_id }}">
                        删除
                    </button>
                    <button class="edit-btn" data-sequence-id="{{ item.sequence_id }}">修改</button> 
                </td>                
                </tr>
                {% endfor %}
            <!-- </thead> -->
            <tbody>
            </tbody>
        </table>
    </div>
    {% endif %}          
    <span class="paging"></span>
    <!-- <div class="add">
        <ul class="content">
            <li class="close">X</li>
            <li><span>学科</span> <select name="subject" id=""></select></li>

            <li class="questionType"><span>题型</span>
                <ul class="radio">
                    <li><label for="radio"><input type="radio" name="questionType" id="radio" value="radio"> <label for="radio" id="radioText">单选</label></label>
                    </li>
                    <li><label for="checkbox"><input type="radio" name="questionType" id="checkbox" value="checkbox"><label for="checkbox" id="checkboxText">多选</label></label>
                    </li>
                    <li><label for="short-answer"><input type="radio" name="questionType" id="short-answer" value="short-answer"><label for="short-answer" id="short-answerText">简答</label></label>
                    </li>
                </ul>
            </li>

            <li class="options">
                <span>上传图片</span>
                <input type="file" id="file">
                <div class="img"><img src="" alt=""></div>
            </li>
            <li><button class="uploadEdit">更改</button></li>
        </ul>

    </div> -->






</body>
<script src="static/lib/jQuerymini.js"></script>
<script src="static/js/baseAPI.js"></script>
<script src="static/js/index.js"></script>
<script src="static/js/utils.js"></script>
<script>
// 确保在文档加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
    // 为删除按钮添加事件监听器
    document.querySelectorAll('.delete-btn').forEach(function(button) {
        button.addEventListener('click', function() {
            var sequenceId = this.getAttribute('data-sequence-id');
            // 调用删除函数，传递序列ID
            alert("删除成功")
            // Del(sequenceId);
        });
    });
 
    // 为修改按钮添加事件监听器（这里只是示例，需要您实现具体的修改功能）
    document.querySelectorAll('.edit-btn').forEach(function(button) {
        button.addEventListener('click', function() {
            var sequenceId = this.getAttribute('data-sequence-id');
            // 调用修改函数或执行其他操作，传递序列ID
            // Edit(sequenceId); // 假设您有一个Edit函数
            alert('修改成功，序列ID: ' + sequenceId);
        });
    });

    document.querySelectorAll('.add-btn').forEach(function(button) {
        button.addEventListener('click', function() {
            var sequenceId = this.getAttribute('data-sequence-id');

          window.location.href="/add"

            // 调用修改函数或执行其他操作，传递序列ID
            // Edit(sequenceId); // 假设您有一个Edit函数
             alert('修改功能尚未实现，序列ID: ' + sequenceId); 
        });


    document.querySelectorAll('.dels-btn').forEach(function(button) {
        button.addEventListener('click', function() {
            var sequenceId = this.getAttribute('data-sequence-id');
            var checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
            var selectedValues = [];
            checkboxes.forEach(function(checkbox) {
            selectedValues.push(checkbox.value);
        });
            console.log(selectedValues);
            // 调用修改函数或执行其他操作，传递序列ID
            // Edit(sequenceId); // 假设您有一个Edit函数
            alert('删除成功，序列ID: ' + selectedValues);
            fetch('/equipment/del', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                eq_id_list: selectedValues
            })
            })
            .then(response => response.json())
            .then(data => {
                console.log('Success:', data);
            })
            .catch((error) => {
                console.error('Error:', error);
            });
        });
    });
    
    
});


document.querySelectorAll('input[type="checkbox"]').forEach(function(checkbox) {
        checkbox.addEventListener('change', function() {
            var form = this.closest('form');
            var submitButton = form.querySelector('button[type="submit"]');
            var checkedCount = form.querySelectorAll('input[type="checkbox"]:checked').length;
            submitButton.disabled = checkedCount === 0;
        });
    });
})
/*
 // 定义删除函数（这里只是示例，需要您实现与后端的通信） 
 function Del(sequenceId)  }
     // 发送AJAX请求到服务器以删除指定的序列 
     // ... 
     alert('正在删除序列ID: ' + sequenceId); // 仅用于演示 
})
*/
 
// 如果需要，也可以定义修改函数
// function Edit(sequenceId) {
//     // 实现修改逻辑
// }
</script>

</html>